package com.example.config.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author ：fbb
 * @version ：1.0
 * @since 2021-11-29 17:11
 */
@Component
@Slf4j
public class MyMetaHander implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("开始插入");
        this.setInsertFieldValByName("createTime",new Date(),metaObject);
        this.setInsertFieldValByName("updateTime",new Date(),metaObject);
//        this.setInsertFieldValByName("userName","fanbinbing",metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("开始更新");
        this.setUpdateFieldValByName("updateTime",new Date(),metaObject);
    }
}
